package com.xdap.fsapproval.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xdap.common.pojo.dto.DataResponse;
import com.xdap.common.pojo.dto.webhook.WebhookProcessDto;
import com.xdap.fsapproval.service.AsagelSendApprovalSertvice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


/**
 * @BelongsProject: com.xdap.cyms.orgUser.controller
 * @Author: liuyang
 * @CreateTime: 2022/9/2 12:13
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/custom/asagel/sendapproval")
public class SendApprovalController {

    @Autowired
    AsagelSendApprovalSertvice asagelSendApprovalSertvice;

    /*
     * 实际使用的接口
     */
    @PostMapping("/webhook")
    public DataResponse webhook(@RequestBody HashMap<String, Object> hashMap) {
        log.info("接受webHook推送数据:" + JSONObject.toJSONString(hashMap));
        WebhookProcessDto webhookProcessDto = JSONObject.toJavaObject(JSON.parseObject(JSONObject.toJSONString(hashMap)), WebhookProcessDto.class);
        //   log.info("接受webHook推送数据转换实体类："+JSONObject.toJSONString(webhookProcessDto));
        asagelSendApprovalSertvice.sendApproval(webhookProcessDto);
        return DataResponse.ok();
    }

    @PostMapping("/testWebhook")
    public DataResponse testWebhook(@RequestBody HashMap<String, Object> map) {
        log.info("接受webHook推送数据：" + JSONObject.toJSONString(map));
        return DataResponse.ok();
    }

    @GetMapping("/compensateSend")
    public DataResponse compensateSend(@RequestParam("documentId") String documentId) {
        asagelSendApprovalSertvice.compensateSend(documentId);
        return DataResponse.ok();
    }
}
